/**
 * Created with IntelliJ IDEA.
 * Description:
 * User: 87111
 * Date: 2025-11-01
 * Time: 17:15
 */
//懒汉式
class SingletonLazy {
    private static SingletonLazy instance = null;
    private static Object locker = new Object();
    public static SingletonLazy getInstance() {
        if(instance == null) {
            synchronized(locker) {
                if(instance == null) {
                    instance = new SingletonLazy();
                }
            }
        }
        return instance;
    }
    private SingletonLazy() {
    }
}
public class Demo2 {
    public static void main(String[] args) {
        //正确使用
        SingletonLazy.getInstance();
//        //报错
//        SingletonLazy singletonLazy = new SingletonLazy();
    }
}
